export function getStyle(obj, key) {
  return (obj.currentStyle || getComputedStyle(obj))[key]
}

export function getOverflowAutoEl(el) {
  if (getStyle(el, "overflow") !== "auto") {
    el = el.parentNode
    return getOverflowAutoEl(el)
  }
  return el
}

export function getPosition(el, parentEl) {
  let top = 0
  let left = 0
  while (el && (parentEl && el !== parentEl)) {
    top += el.offsetTop
    left += el.offsetLeft
    el = el.offsetParent
  }
  return {
    top,
    left
  }
}

export function scrollToEle(el,parentEl,dir='top'){ 
  const position = getPosition(el, parentEl);
  const num= position[dir]
  parentEl['scroll'+[dir.replace(/^[a-z]/,s=>s.toUpperCase())]] =  num
  return num
}
